package com.zhanghu.model;

import com.zhanghu.model.computer.AsusComputer;
import com.zhanghu.model.computer.Computer;
import com.zhanghu.model.computer.DellComputer;
import com.zhanghu.model.computer.HpComputer;
import com.zhanghu.model.factory.ComputerFactory;

/**
 * @Author: zhanghu
 * @Description: 简单工厂测试类
 * @Date: Create in 16:04 2020/1/14
 * @modified by:
 */
public class ComputerTest {
    public static void main(String[] args) {
        //asus华硕
        //这里其实有两步
        //1.通过new ComputerFactory()获取工厂对象
        //2.通过调用getComputer()方法获取电脑对象,即：
        //ComputerFactory computerFactory = new ComputerFactory();
        //Computer asusComputer = computerFactory.getComputer("asus");
        //asusComputer.brand();
        Computer asusComputer = new ComputerFactory().getComputer("asus");
        asusComputer.brand();
        //hp惠普
        Computer hpComputer = new ComputerFactory().getComputer("hp");
        hpComputer.brand();
        //dell戴尔
        Computer dellComputer = new ComputerFactory().getComputer("dell");
        dellComputer.brand();

        //测试反射创建对象
        //asus华硕
        asusComputer = new ComputerFactory().getComputer(AsusComputer.class);
        asusComputer.brand();
        //hp惠普
        hpComputer = new ComputerFactory().getComputer(HpComputer.class);
        hpComputer.brand();
        //dell戴尔
        dellComputer = new ComputerFactory().getComputer(DellComputer.class);
        dellComputer.brand();

        System.out.println("--------------------------------------------------------------");
        //通过静态方法获取对象
        //asus华硕
        asusComputer = ComputerFactory.getStaticComputer("asus");
        asusComputer.brand();
        //hp惠普
        hpComputer = ComputerFactory.getStaticComputer("hp");
        hpComputer.brand();
        //dell戴尔
        dellComputer = ComputerFactory.getStaticComputer("dell");
        dellComputer.brand();


        //测试反射创建对象
        //asus华硕
        asusComputer = ComputerFactory.getStaticComputer(AsusComputer.class);
        asusComputer.brand();
        //hp惠普
        hpComputer = ComputerFactory.getStaticComputer(HpComputer.class);
        hpComputer.brand();
        //dell戴尔
        dellComputer = ComputerFactory.getStaticComputer(DellComputer.class);
        dellComputer.brand();


    }
}
